package com.jshcbd.modules.asset.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jshcbd.modules.asset.entity.RetrocedeEntity;
import com.jshcbd.modules.asset.vo.RetrocedeVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @author zhoucd
 * @date
 * @description
 */
public interface RetrocedeMapper extends BaseMapper<RetrocedeEntity> {

    @Select("SELECT B.*,C.NAME COMPANY_NAME FROM RETROCEDE_ITEM A " +
            "LEFT JOIN RETROCEDE B ON B.ID = A.MAIN_ID " +
            "LEFT JOIN COMPANY C ON B.COMPANY_ID = C.ID " +
            "WHERE A.ASSET_ID = #{assetId} " +
            "ORDER BY B.CREATE_TIME")
    IPage<RetrocedeVo> queryViewByAssetId(Page<RetrocedeVo> page, String assetId);


    @Select("SELECT * FROM (SELECT B.*,C.NAME COMPANY_NAME FROM RETROCEDE B " +
            "LEFT JOIN COMPANY C ON B.COMPANY_ID = C.ID " +
            "ORDER BY B.CREATE_TIME) TEMP ${ew.customSqlSegment} ")
    IPage<RetrocedeVo> queryPageView(Page<RetrocedeVo> page, @Param(Constants.WRAPPER) Wrapper wrapper);

}
